<template>
  <view class="container">
    <view class="bg"></view>
    <view class="icon">
      <image
        src="http://jy-nfc.oss-cn-hangzhou.aliyuncs.com/2024/12/26/8f6eb92db9ab4aedb4ef93f78c5898b3.png"
        mode="aspectFill"
      />
    </view>
    <view class="login">
      <text class="loginOA">OA工作平台</text>
      <text class="loginContent">为你们提供更方便的服务，更安心的未来</text>
      <button
        class="loginBtn"
        type="primary"
        open-type="getPhoneNumber"
        @getphonenumber="getPhoneNumber"
      >
        手机号快捷登录
      </button>
      <!-- <button class="loginBtn loginBtno" @tap="noLogin">暂不登录</button> -->
    </view>
  </view>
</template>

<script>
const app = getApp();
export default {
  data() {
    return {};
  },
  methods: {
    noLogin() {
      app.navigationTo("pages/index/index");
    },
    getPhoneNumber(e) {
      let that = this;
      if (e.detail.code) {
        wx.login({
          success(login) {
            if (login.code) {
              //发起网络请求
              uni.request({
                url: "https://4949rlat3853.vicp.fun/app/nfc/wx/login",
                method: "POST",
                data: {
                  authCode: login.code,
                  wxPhoneCode: e.detail.code,
                },
                success(res) {
                  if (res.data.code == 500) {
                    uni.showModal({
                      title: "友情提示",
                      content: res.data.msg,
                      showCancel: false,
                    });
                    return false;
                  }
                  console.log("res", res.data.data);
                  uni.setStorageSync("token", res.data.data.token);
                  that.$store.commit("SET_TOKEN", res.data.data.token);
									that.$store.commit("SET_FLAG", res.data.data.merchantFlag);
									that.$store.commit("SET_USERID", res.data.data.userId);
                  uni.$emit("update");
                  app.navigationTo("pages/index/index");
                },
                fail(err) {
                  uni.showModal({
                    title: "友情提示",
                    content: err,
                    showCancel: false,
                  });
                },
                complete() {
                  console.log("接口:  nfc/wx/login", "入参:", {
                    authCode: login.code,
                    wxPhoneCode: e.detail.code,
                  });
                },
              });
            } else {
              console.log("登录失败！" + res.errMsg);
            }
          },
        });
      }
    },
  },
};
</script>

<style lang="scss">
.container {
  min-height: 100vh;
  width: 100vw;
  padding-top: 422rpx;
  box-sizing: border-box;
  background: #ffffff;
  position: relative;
  z-index: 1;

  .bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 750rpx;
    height: 989rpx;
    background: linear-gradient(
      162deg,
      #71a5ff 0%,
      #ffffff 43%,
      #dec7ff 60%,
      #ffffff 80%
    );
    z-index: -1;
  }
}

.icon {
  width: 522rpx;
  height: 478rpx;
  margin: 0 auto;
  margin-bottom: 192rpx;

  image {
    height: 100%;
    width: 100%;
  }
}

.login {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200rpx;
  width: 100%;

  .loginOA {
    font-weight: 700;
    font-size: 40rpx;
    color: #000000;
    line-height: 32rpx;
    text-align: center;
    margin-bottom: 28rpx;
  }

  .loginContent {
    font-weight: 500;
    font-size: 28rpx;
    color: #565656;
    line-height: 44rpx;
    text-align: center;
    margin-bottom: 48rpx;
  }

  .loginBtn {
    flex-shrink: 0;
    width: 320rpx;
    height: 96rpx;
    background: linear-gradient(180deg, #886ae6 0%, #4635ff 99%);
    border-radius: 48rpx;
    font-weight: 400;
    font-size: 32rpx;
    color: #ffffff;
    line-height: 96rpx;
    text-align: center;
  }

  .loginBtno {
    background: none;
    border: 2rpx solid #4e5969;
    color: #4e5969;
    margin-top: 20rpx;
  }
}
</style>
